;
; Copyright (c) Microsoft Corporation.  All rights reserved.
;
;
; Use of this sample source code is subject to the terms of the Microsoft
; license agreement under which you licensed this sample source code. If
; you did not accept the terms of the license agreement, you are not
; authorized to use this sample source code. For the terms of the license,
; please see the license agreement between you and Microsoft or, if applicable,
; see the LICENSE.RTF on your install media or the root of your tools installation.
; THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
;
;
; (C) Copyright 2006 Marvell International Ltd.
; All Rights Reserved
;
; Copyright (c) 1998, 1999 ARM Limited
; All Rights Reserved
;

    OPT     2       ; disable listing
    INCLUDE kxarm.h
    OPT     1       ; reenable listing
    OPT     128     ; disable listing of macro expansions
    INCLUDE armmacros.s

    TEXTAREA

    LEAF_ENTRY	XScaleCleanDCacheLinesL2
;++
; Routine Description:
;    Clean some number of Data Cache lines (i.e. write back and un-dirty.  Will still hit)
;
; Syntax:
;	void XScaleCleanDCacheLinesL2(PVOID pAddr, DWORD dwLength, DWORD dwLineLength);
;
; Arguments:
;	pAddr -- virtual address at which to start cleaning, on dwLineLength-byte 
;            alignment
;	dwLength -- number of bytes to cleaning, must be > zero
;   dwLineLength -- number of bytes in a cache line
;
; Return Value:
;	-- none --
; r0..r2 junk
; CC flags junk	
;--

    ; clean the range of lines
10
    mcr 	p15, 0, r0, c7, c10, 1  ; clean each entry

 IF {TRUE}    
	; for L2
	mcr     p15, 1, r0, c7, c11, 1
 ENDIF
 	    
    add  r0, r0, r2              ; on to the next line
    subs	r1, r1, r2              ; reduce the number of bytes left
    bgt  %b10                    ; loop while > 0 bytes left

    mcr     p15, 0, r2, c7, c10, 4      ; data write barrier
    
    RETURN
 
     LEAF_ENTRY	XScaleCleanDCacheLines
;++
; Routine Description:
;    Clean some number of Data Cache lines (i.e. write back and un-dirty.  Will still hit)
;
; Syntax:
;	void XScaleCleanDCacheLines(PVOID pAddr, DWORD dwLength, DWORD dwLineLength);
;
; Arguments:
;	pAddr -- virtual address at which to start cleaning, on dwLineLength-byte 
;            alignment
;	dwLength -- number of bytes to cleaning, must be > zero
;   dwLineLength -- number of bytes in a cache line
;
; Return Value:
;	-- none --
; r0..r2 junk
; CC flags junk	
;--

    ; clean the range of lines
10
    mcr 	p15, 0, r0, c7, c10, 1  ; clean each entry
 	    
    add  r0, r0, r2              ; on to the next line
    subs	r1, r1, r2              ; reduce the number of bytes left
    bgt  %b10                    ; loop while > 0 bytes left

    mcr     p15, 0, r2, c7, c10, 4      ; data write barrier
    
    RETURN
    
    
    END
